<?php

namespace app\admin\model;
use think\Model;
use think\Db;

class Index extends Model{
    public function Index(){
    }

    /**添加分类
     * @param $category
     * @return bool
     */
    public function Categorys($category){
        if (empty($category['wa_type']) || empty($category['wa_standard']) || empty($category['wa_model'])){
            return false;
        }
        $fenlei = Db::name('car_wash')
            ->where([
                'wa_standard'=>$category['wa_standard'],
                'wa_model'=>$category['wa_model'],
                'wa_type'=>$category['wa_type']
            ])
            ->find();
        if ($fenlei){return false;}
        $category['wa_time'] = time();
        Db::name('car_wash')->insert($category);
        return true;
    }

    /**添加卷
     * @param $add
     * @return bool
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function Adds($add,$target){
        if (empty($add['vs_content']) || empty($add['vs_price'])){
            return false;
        }
        $shop = Db::table('yc_store')->where('ma_name',$add['vs_name'])->field('ma_id,ma_logo')->find();
        $add['st_id'] = $shop['ma_id'];
        $add['vs_picture'] = $target;
        $add_plus = $this->increases($add);
        Db::name('car_volume_store')->insert($add_plus);
        return true;
    }

    /**
     * 查询店铺
     */
    public function Shop(){
        $shop = Db::name('store')->field('ma_id,ma_name,ma_logo')->where('ma_state',1)->select();
        return !empty($shop) ? $shop : false;
    }
    /**查询分类
     * @param $wa_type
     * @return array/PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function Fenlei($wa_type ){
        $shop = Db::name('car_wash')->where('wa_type',$wa_type)->select();
        return !empty($shop) ? $shop : false;
    }
    public function modifys($vs_id,$move){
        if (is_numeric($vs_id) || is_numeric($move)){
            if ($move == '1'){
                $modify = Db::name('car_volume_store')->where('vs_id',$vs_id)->find();
                if ($modify){
                    return $modify;
                }else {
                    return false;
                }
            }

        } else {
            return false;
        }
    }
    public function modifys_two($whole){
        foreach ($whole as $k=>$v){
            if ($v == ''){
                return false;
            }
        }
        $add = $this->increases($whole);
        $modifys_two = Db::name('car_volume_store')->where('vs_id',$whole['vs_id'])->update($add);
        if ($modifys_two){
            return true;
        }
        return false;
    }
        public function increases($add){
            $add_plus['st_id'] = $add['st_id'];
            $add_plus['vs_content'] = $add['vs_content'];
            $add_plus['vs_time'] = time();
            $add_plus['vs_price'] = $add['vs_price'];
            $add_plus['vs_picture'] = $add['vs_picture'];
            $add_plus['vs_type'] = $add['vs_type'];
            $add_plus['vs_standard'] = $add['vs_standard'];
            $add_plus['vs_model'] = $add['vs_model'];
            $add_plus['vs_name'] = $add['vs_name'];
            $add_plus['vs_surplus'] = $add['vs_surplus'];
            $add_plus['number'] = 1;
            return $add_plus;
        }

}